<?php 
session_start();
// 检查是否登录
if (!isset($_SESSION['user_id'])) {
    header('Location: login.php');
    exit;
}

include 'config.php';

// 检查文章ID
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
    header('Location: index.php');
    exit;
}

$articleId = $_GET['id'];

// 删除文章
try {
    $stmt = $pdo->prepare("DELETE FROM aiwz_articles WHERE id = :id");
    $stmt->bindParam(':id', $articleId);
    $stmt->execute();
} catch(PDOException $e) {
    die("删除失败: " . $e->getMessage());
}

// 重定向到首页
header('Location: index.php?deleted=1');
exit;
?>
